package com.sky.controller.courier;

import com.sky.result.Result;
import com.sky.service.courier.CourierTradeOrderService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Description DispatchController
 * @Author lyh
 * @Date 2024-11-05
 */
@RestController
@ApiOperation("查看骑手位置")
public class DispatchController {
    @Autowired
    private CourierTradeOrderService tradeOrderService;

    @GetMapping("/dispatch/loadRouteInfo")
    @ApiOperation("查看骑手位置")
    public Result<String> loadRouteInfo(String tradeNo, Long courierId) {
        String res = tradeOrderService.loadRouteInfo(tradeNo, courierId);
        return Result.success(res);
    }

    @GetMapping("/r/{code}")
    public void shortUrl(@PathVariable("code") String code, HttpServletResponse response) {
       String longUrl=tradeOrderService.getLongUrl(code);
        try {
            response.sendRedirect(longUrl);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
